<?php
if (!$export) {

    function nf($value) {
        return number_format($value,2);
    }

    $date_picker->__dateFormat = "yy-mm-dd";
    echo "<scr" . "ipt type=\"text/javascript\">";
    $date_picker->generateDP("srcPeriodStart");
    $date_picker->generateDP("srcPeriodEnd");
    echo "</scr" . "ipt>";
    $date_picker->init();
} else {

    function nf($value) {
        return number_format($value,2);
    }

    header('Content-type: application/octet-stream');
    header('Content-Disposition: attachment; filename="pembelian_customer_' . '_' . date('(d M Y)', strtotime($srcPeriodEnd)) . '.xls"');
    header('Pragma: no-cache');
    header('Expires: 0');
}
?>
<?php echo $breadcrumb; ?>

<link type="text/css" rel="stylesheet" href="<?php echo base_url(); ?>library/style_lap.css" />
<div id="content">
    <div class="DivTable">
        <table id="hor-minimalist-b" border="0">
            <tr>
                <td width="5%"></td>
                <td width="20%"></td>
                <td width="30%"></td>
                <td width="15%"></td>
                <td width="15%"></td>
                <td width="15%"></td>
            </tr>
            <?php
            if (!$export) {
                ?>
                <tr>  
                    <td style="padding: 5px 0px;" align="left" colspan="3">
                        <form name="fCari" id="fCari" action="" method="get" >                        
                            <span style="font-size:12px">Dari</span>
                            <input class="read-only" type="text" name="srcPeriodStart" id="srcPeriodStart" value="<?php echo $srcPeriodStart; ?>" maxlength="10" size="10" readonly="readonly"  />                        
                            <span style="font-size:12px">Sampai</span>
                            <input class="read-only" type="text" name="srcPeriodEnd" id="srcPeriodEnd" value="<?php echo $srcPeriodEnd; ?>" maxlength="10" size="10" readonly="readonly"  />
                            <input type="submit" value="cari">
                        </form>                    
                    </td>
                    <td align="right" colspan="5">
                        <form name="fCari" id="fCari" action="" method="post">
                            <input type="hidden" name="export" value="1">
                            <input type="hidden" name="srcPeriodEnd" value="<?= $srcPeriodEnd ?>">
                            <input type="hidden" name="srcPeriodStart" value="<?= $srcPeriodStart ?>">
                            <input type="submit" value="export">
                        </form>
                    </td>
                </tr>
<?php } ?>
            <tr>
                <td colspan="6" align="center">PT ANUGERAH DINDA LESTARI</td>
            </tr>
            <tr>
                <td colspan="6" align="center">LAPORAN PENJUALAN</td>
            </tr>
            <tr>
                <td colspan="6" align="center">Untuk Periode <?php
                    echo date('d M Y', strtotime($srcPeriodStart))." s.d ". date('d M Y', strtotime($srcPeriodEnd));;
                    ?></td>
            </tr>
            <tr>
                <td width="5%">No</td>                
                <td>Nama Pelanggan</td>
                <td>Alamat/Telp Pelanggan</td>
                <td align="right">Total Pembelian Item</td>
                <td align="right">Total Nominal Penjualan (Rp)</td>
                <td align="right">Total Nominal Penjualan ($)</td>
            </tr>
            <?php
            $i = 1;
            foreach ($belanja_supplier as $row) {
                echo "
                        <tr>
                            <td>$i</td>
                            <td>" . $row->nama_customer . "</td>
                            <td>" . $row->alamat_customer . "/".$row->telepon_customer."</td>
                            <td align='right'>" . ($row->jumlah_item) . " Item</td>
                            <td align='right'>Rp " . nf($row->harga_beli) . "</td>
                            <td align='right'>$ " . nf($row->harga_beli_dollar) . "</td>
                        </tr>
                        ";
                $i++;
            }
            ?>
        </table>
    </div>
    <br class="bersih" />
</div>